package com.snowflakes.gruntr;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;


public class GruntAdapter extends ParseQueryAdapter<ParseObject> {

	
	public GruntAdapter(final Context context, final String parentID) {
		// Use the QueryFactory to construct a PQA that will only show
		// Todos marked as high-pri
		super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
			public ParseQuery create() {
				
				ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Grunt");
				query.whereEqualTo("ParentPost", parentID);
				query.addAscendingOrder("createdAt");
				return query;
			}
		});
	}


	// Customize the layout by overriding getItemView
	@Override
	public View getItemView(ParseObject object, View v, ViewGroup parent) {
		if (v == null) {
			v = View.inflate(getContext(), R.layout.individual_grunt, null);
		}

		super.getItemView(object, v, parent);

		// Add the title view
		TextView titleTextView = (TextView) v.findViewById(R.id.tvGruntName);
		titleTextView.setText(object.get("Name").toString());
		
		TextView date = (TextView) v.findViewById(R.id.tvGruntDate);
		date.setText(object.getCreatedAt().toString());
		
		Button playIt = (Button) v.findViewById(R.id.playGrunt);
		playIt.setTag(object.getObjectId());
		
		return v;
	}
	
	

}

